package railRoad.web.slaves;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import railRoad.Route;
import railRoad.Schedule;
import railRoad.web.slaves.interfaces.ISlaveServlet;
import railRoad.worker.FactoryRW;

public class RouteCreateServlet implements ISlaveServlet {

	public void work(HttpServletRequest req, HttpServletResponse resp)
			throws IOException, ServletException {

		Map<?, ?> parameterMap = req.getParameterMap();

		if (parameterMap.containsKey("tickets")) {

			int avalable = Integer.parseInt(req.getParameterValues("tickets")[0]); 

			Route route = new Route(0, avalable);

			Schedule schedule = Schedule.getInstance();
			schedule.addRoute(route);

			FactoryRW.insert(route, 0);
		}//if parametersMap
		resp.sendRedirect("/pages/create_order.do");
	}//work

}//RouteCreateServlet
